﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using Shiloh.Job.Services.Models;
using SqlSugar;
namespace Shiloh.Job.Model.Entities
{
    public abstract class User
    {
        public const int MaxLoginFailCount = 3;
        public const int LockMinutes = 30;
        public const int AttempMinutes = 30;

        public delegate void ValidLoginFailDelegate(User? user, string errorMsg);
        public ValidLoginFailDelegate OnLoginFail;
        /// <summary>
        /// 用户的唯一标识 ID
        /// </summary>
        [SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = false)]
        [Display(Name = "用户 ID")]
        public Guid Id { get; set; } = Guid.NewGuid();

        /// <summary>
        /// 用户的手机号码，用于注册、登录和接收通知等
        /// </summary>
        [Required(ErrorMessage = "手机号码是必填项")]
        [Phone(ErrorMessage = "请输入有效的手机号码")]
        [Display(Name = "手机号码")]
        public string PhoneNumber { get; set; }

        /// <summary>
        /// 用户的登录用户名，在系统中必须唯一
        /// </summary>
        [Required(ErrorMessage = "用户名是必填项")]
        [StringLength(50, MinimumLength = 3, ErrorMessage = "用户名长度必须在 3 到 50 个字符之间")]
        [Display(Name = "用户名")]
        public string Username { get; set; }

        /// <summary>
        /// 用户的登录密码，用于保护用户账户安全
        /// </summary>
        [Required(ErrorMessage = "密码是必填项")]
        [StringLength(100, MinimumLength = 6, ErrorMessage = "密码长度必须至少为 6 个字符")]
        [Display(Name = "密码")]
        public string Password { get; set; }

        /// <summary>
        /// 用户的电子邮件地址，用于接收系统通知和重置密码等操作
        /// </summary>
        [EmailAddress(ErrorMessage = "请输入有效的电子邮件地址")]
        [Display(Name = "电子邮件地址")]
        public string Email { get; set; }

        /// <summary>
        /// 用户登录失败的次数，用于限制登录尝试次数
        /// </summary>
        [Display(Name = "登录失败次数")]
        public int LoginFailCount { get; set; }

        public bool IsLocked { get; set; }
    }

}
